#user  nobody;
user root root;
worker_processes  1;

  #error_log  logs/error.log;
  #error_log  logs/error.log  notice;
  #error_log  logs/error.log  info;

  #pid        logs/nginx.pid;


events {
worker_connections  1024;
}


  http {
  include       mime.types;
  default_type  application/octet-stream;

  #包含redis初始化模块
  lua_shared_dict dis_cache 128m;  #共享内存开启

  #限流设置
  #binary_remote_addr 是一种key，表示基于 remote_addr(客户端IP) 来做限流，binary_ 的目的是压缩内存占用量。
  limit_req_zone $binary_remote_addr zone=contentRateLimit:10m rate=10r/s;

  #根据IP地址来限制，存储内存大小10M，配置名为perip，大小为1m
  limit_conn_zone $binary_remote_addr zone=perip:10m;
  
  #根据IP地址来限制，存储内存大小10M，配置名为perserver，大小为1m
  limit_conn_zone $server_name zone=perserver:10m;

  #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
  #                  '$status $body_bytes_sent "$http_referer" '
  #                  '"$http_user_agent" "$http_x_forwarded_for"';

  #access_log  logs/access.log  main;


  #keepalive_timeout  0;
  keepalive_timeout  65;

  server {
	  listen       80;
	  server_name       static.xiaohong.work;

	  proxy_set_header X-Forwarded-Host $host;
	  proxy_set_header X-Forwarded-Server $host;
	  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

	  location / {
		  root   /root/static;
		  #允许跨域请求的域，*代表所有
		  add_header 'Access-Control-Allow-Origin' *;
		  #允许带上cookie请求
		  add_header 'Access-Control-Allow-Credentials' 'true';
		  #允许请求的方法，比如GET/POST/PUT/DELETE
		  add_header 'Access-Control-Allow-Methods' *;
		  #允许请求的header
		  add_header 'Access-Control-Allow-Headers' *;
		  if ($request_method = 'OPTIONS') {
			  return 204;
		  }
		  index  index.html index.htm;
	  }
  }

  server {
	  listen       80;
	  server_name       search.xiaohong.work;

	  proxy_set_header X-Forwarded-Host $host;
	  proxy_set_header X-Forwarded-Server $host;
	  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

	  location / {
		  proxy_pass http://47.93.213.92:18086;
		  proxy_connect_timeout 600;
		  proxy_read_timeout 600;
	  }
  }
  
  
  server {
	  listen       80;
	  server_name       test.xiaohong.work;

	  proxy_set_header X-Forwarded-Host $host;
	  proxy_set_header X-Forwarded-Server $host;
	  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

	  location / {
		  proxy_pass http://119.29.67.157:18888;
		  proxy_connect_timeout 600;
		  proxy_read_timeout 600;
	  }
  }

  server {
	  listen       80;
	  server_name       gateway.xiaohong.work;
	  rewrite ^(.*)$ https://$host$1; #将所有HTTP请求通过rewrite指令重定向到HTTPS。

	  proxy_set_header X-Forwarded-Host $host;
	  proxy_set_header X-Forwarded-Server $host;
	  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

	  location / {
		  proxy_pass http://47.102.218.218:8001;
		  proxy_connect_timeout 600;
		  proxy_read_timeout 600;
	  }
  }

  server {
	  listen       80;
	  server_name       file.xiaohong.work;
	  rewrite ^(.*)$ https://$host$1; #将所有HTTP请求通过rewrite指令重定向到HTTPS。

	  proxy_set_header X-Forwarded-Host $host;
	  proxy_set_header X-Forwarded-Server $host;
	  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

	  location / {
		proxy_pass   http://127.0.0.1:8080;
	  }
  }

  server {
	  listen       80;
	  server_name       page.xiaohong.work;

	  proxy_set_header X-Forwarded-Host $host;
	  proxy_set_header X-Forwarded-Server $host;
	  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

		location / {
			# 先找本地
			root  /root/page;
			if (!-f $request_filename) { #请求的文件不存在，就反向代理
				proxy_pass http://47.93.213.92:18084;
				#proxy_pass https://www.baidu.com;
				break;
			}
    	}
  }

  server {
	  listen       80;
	  server_name       api.xiaohong.work;
	  rewrite ^(.*)$ https://$host$1; #将所有HTTP请求通过rewrite指令重定向到HTTPS。

	  proxy_set_header X-Forwarded-Host $host;
	  proxy_set_header X-Forwarded-Server $host;
	  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

	  location / {
		  root   /root/docker/tomcat/webapps/xiaohong_shop_cmm;
		  index  index.html index.htm;
	  }
  }

  server {
      listen       80;
	  server_name       gupiao.xiaohong.work;
	  rewrite ^(.*)$ https://$host$1; #将所有HTTP请求通过rewrite指令重定向到HTTPS。

	  proxy_set_header X-Forwarded-Host $host;
	  proxy_set_header X-Forwarded-Server $host;
	  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

	  location / {
		  root   /root/docker/tomcat/webapps/xiaohong_gupiao;
		  index  index.html index.htm;
	  }
  }

  server {
      listen       80;
      server_name  www.xiaohong.work;
	  rewrite ^(.*)$ https://$host$1; #将所有HTTP请求通过rewrite指令重定向到HTTPS。
	  
	  proxy_set_header X-Forwarded-Host $host;
	  proxy_set_header X-Forwarded-Server $host;
	  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

  #charset koi8-r;
  #access_log  logs/host.access.log  main;

  location / {
	  root  /root/docker/tomcat/webapps/XiaoHong_portal;
	  add_header Access-Control-Allow-Origin *;
	  add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS, PUT, DELETE';
	  add_header Access-Control-Allow-Headers *;
	  if ($request_method = 'OPTIONS') {
	      return 204;
	  }
	  index  index.html index.htm;
  }

  location /static {
	  root   /root/static;
	  index  index.html index.htm;
  }

  location /search {
	  proxy_pass http://47.93.213.92:18086;
	  proxy_connect_timeout 600;
	  proxy_read_timeout 600;
  }

  location /page {
	  root   /root/page;
	  index  index.html index.htm;
  }


  #location /api {
  #    #proxy_pass
  #    root  /root/docker/tomcat/webapps/xiaohong_shop_cmm;
  #    proxy_connect_timeout 600;
  #    proxy_read_timeout 600;
  #}


  #location / {
  #      #proxy_pass   http://127.0.0.1:8001;
  #      root  /root/static;
  #      #proxy_connect_timeout 600;
  #      #proxy_read_timeout 600;
  #      index  index.html index.htm;
  #}



  #用户请求/update_content?id=1, 将该请求给/root/lua/update_content.lua脚本处理
  location /update_content {
	  content_by_lua_file  /root/lua/update_content.lua;
  }

  location /read_content {
	  content_by_lua_file /root/lua/read_content.lua;
	  #nodelay，配合burst使用，并发处理不延迟，不按(1s/rate)秒/个的速率处理，等到完成之后，按照正常的速率处理
	  limit_req zone=contentRateLimit burst=4 nodelay; #使用限流配置
  }

  location /brand {
	  #limit_conn addr 5;
	  limit_conn perip 10;   #设置单个客户端ip与服务器的连接数为10．
	  limit_conn perserver 100; #限制与服务器的总连接数为100
	  #表示这个请求给180主机处理，因为程序运行在主机上，不在虚拟机上
	  proxy_pass http://192.168.43.229:18081;
  }


  #location ~ /xiaohong {
  #     root /data/fast_data/data;
  #     ngx_fastdfs_module;
  #     #禁止缓存
  #     add_header Cache-Control no-store;
  #}

  #error_page  404              /404.html;

  # redirect server error pages to the static page /50x.html
  #
  error_page   500 502 503 504  /50x.html;
  location = /50x.html {
  root   html;
  }

  # proxy the PHP scripts to Apache listening on 127.0.0.1:80
  #
  #location ~ \.php$ {
  #    proxy_pass   http://127.0.0.1;
  #}

  # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
  #
  #location ~ \.php$ {
  #    root           html;
  #    fastcgi_pass   127.0.0.1:9000;
  #    fastcgi_index  index.php;
  #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
  #    include        fastcgi_params;
  #}

  # deny access to .htaccess files, if Apache's document root
  # concurs with nginx's one
  #
  #location ~ /\.ht {
  #    deny  all;
  #}
}

  # another virtual host using mix of IP-, name-, and port-based configuration
  #
  #server {
  #    listen       8000;
  #    listen       somename:8080;
  #    server_name  somename  alias  another.alias;

  #    location / {
  #        root   html;
  #        index  index.html index.htm;
  #    }
  #}


  # HTTPS server
  #
  #server {
  #    listen       443 ssl;
  #    server_name  localhost;

  #    ssl_certificate      cert.pem;
  #    ssl_certificate_key  cert.key;

  #    ssl_session_cache    shared:SSL:1m;
  #    ssl_session_timeout  5m;

  #    ssl_ciphers  HIGH:!aNULL:!MD5;
  #    ssl_prefer_server_ciphers  on;

  #    location / {
  #        root   html;
  #        index  index.html index.htm;
  #    }
  #}
  
  
  #以下属性中，以ssl开头的属性表示与证书配置有关。
  server {
      listen 443 ssl;
      #配置HTTPS的默认访问端口为443。
      #如果未在此处配置HTTPS的默认访问端口，可能会造成Nginx无法启动。
      #如果您使用Nginx 1.15.0及以上版本，请使用listen 443 ssl代替listen 443和ssl on。
      server_name www.xiaohong.work; #需要将yourdomain.com替换成证书绑定的域名。
      root html;
	  index index.html index.htm;
      ssl_certificate /root/cert/www/5381922_www.xiaohong.work.pem;  #需要将cert-file-name.pem替换成已上传的证书文件的名称。
      ssl_certificate_key /root/cert/www/5381922_www.xiaohong.work.key; #需要将cert-file-name.key替换成已上传的证书密钥文件的名称。
      ssl_session_timeout 5m;
      ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
      #表示使用的加密套件的类型。
      ssl_protocols TLSv1 TLSv1.1 TLSv1.2; #表示使用的TLS协议的类型。
      ssl_prefer_server_ciphers on;
      location / {
          root  /root/docker/tomcat/webapps/XiaoHong_portal;  #站点目录。
          index index.html index.htm;
      }
  }
  
  
  server {
      listen 443 ssl;
      server_name static.xiaohong.work;
      root html;
  	  index index.html index.htm;
      ssl_certificate /root/cert/static/5382032_static.xiaohong.work.pem;  
      ssl_certificate_key /root/cert/static/5382032_static.xiaohong.work.key; 
      ssl_session_timeout 5m;
      ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
      ssl_protocols TLSv1 TLSv1.1 TLSv1.2; 
      ssl_prefer_server_ciphers on;
	  
      location / {
          root   /root/static;
          index index.html index.htm;
      }
  }
  
  server {
      listen 443 ssl;
      server_name file.xiaohong.work;
      root html;
  	  index index.html index.htm;
      ssl_certificate /root/cert/file/5382077_file.xiaohong.work.pem;  
      ssl_certificate_key /root/cert/file/5382077_file.xiaohong.work.key; 
      ssl_session_timeout 5m;
      ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
      ssl_protocols TLSv1 TLSv1.1 TLSv1.2; 
      ssl_prefer_server_ciphers on;
  	  
      location / {
          proxy_pass   http://127.0.0.1:8080;
      }
  }
  
  
  server {
      listen 443 ssl;
      server_name gateway.xiaohong.work;
      root html;
  	  index index.html index.htm;
      ssl_certificate /root/cert/gateway/5382141_gateway.xiaohong.work.pem;  
      ssl_certificate_key /root/cert/gateway/5382141_gateway.xiaohong.work.key; 
      ssl_session_timeout 5m;
      ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
      ssl_protocols TLSv1 TLSv1.1 TLSv1.2; 
      ssl_prefer_server_ciphers on;
  	  
      location / {
          proxy_pass http://47.102.218.218:8001;
          proxy_connect_timeout 600;
          proxy_read_timeout 600;
      }
  }
  

}
